const { resolve } = require("path")
const CompressionWebpackPlugin = require("compression-webpack-plugin")
const plugins = []
if (process.env.NODE_ENV === '"production')
    plugins.push(
        new CompressionWebpackPlugin({
            filename: "[path].gz[query]",
            algorithm: "gzip",
            test: /\.js$|\.html$|\.css/, // 匹配的文件名
            threshold: 10240, // 文件超过10k，进行gzip压缩
            minRatio: 0.8,
            deleteOriginalAssets: false, // 是否删除原文件
        })
    )
module.exports = {
    productionSourceMap: false,

    devServer: {
        open: true,
        port: 8923,
        // 接口转发到 服务器端口
        proxy: "http://localhost:80",
    },
    publicPath: "",
    pages: {
        index: {
            entry: "src/pages/oj/index.js",
            template: "src/pages/oj/index.html",
            filename: "index.html",
            title: "OnlineJudge",
        },
        admin: {
            entry: "src/pages/admin/index.js",
            template: "src/pages/admin/index.html",
            filename: "admin/index.html",
            title: "OnlineJudge",
        },
    },
    chainWebpack: config => {
        // 移除 prefetch 插件
        config.plugins.delete("prefetch") // 移除 preload 插件
        config.plugins.delete("preload")
    },
    configureWebpack: {
        externals: {
            vue: "Vue",
        },
        resolve: {
            alias: {
                vue$: "vue/dist/vue.esm.js",
                "@": resolve("src"),
                "@oj": resolve("src/pages/oj"),
                "@admin": resolve("src/pages/admin"),
                "~": resolve("src/components"),
            },
        },
        plugins,
    },
}
